#!/bin/bash

set +e

# if [ -z "$1"  ]
# then
#   echo "请设置起始值！"
#   exit 1;
# fi
# # Committing

token=$(/usr/local/bin/lotus-miner auth create-token --perm admin)
method="SectorsListInStates"
# STATUS="PreCommit1"
STATUS="SealPreCommit1Failed"


# curl -X POST \
#   -H "Content-Type: application/json" \
#   -H "Authorization: Bearer $token" \
#   --data '{"jsonrpc":"2.0", "id":2, "method":"Filecoin.'"$method"'", "params":[]}' \
#   'http://127.0.0.1:2345/rpc/v0'



json=`curl -s -X POST \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $token" \
    --data "{\"jsonrpc\":\"2.0\", \"id\":3, \"method\":\"Filecoin.$method\", \"params\": [[\"$STATUS\"]]}" \
    'http://10.0.1.250:5432/rpc/v0'`


list=`echo $json | jq '.result'`;
length=`echo $json | jq '.result|length' `;

echo ""
echo ""
echo "-----------失败扇区-------------->"
echo "扇区:" $list  "==>" $length "个"

for index in `seq 0 $length`
do
	number=`echo $list | jq ".[$index]"`

  if [ "$number" == "null"  ]
  then
    # echo "IS NULL"
    continue
  fi
  echo "扇区号" $number

  sleep 1
  # /usr/local/bin/lotus-miner storage find $number
  # DIRWorker=`/usr/local/bin/lotus-miner storage find $number | grep "URL: http://10.0.1"`

  echo "存储位置与: " $DIRWorker

  sleep 1
  /usr/local/bin/lotus-miner sectors remove --really-do-it $number
done

echo "<-----------密封工人--------------"


# lotus-miner sectors update-state --really-do-it 18 Removing

# lotus-miner sectors update-state --really-do-it  0 Committing

# 删除P1失败扇区
# */1 * * * *  /bin/bash /home/ceshi/miner-sh/miner/miner_rpc_remove_sectors_351.sh >> /home/ceshi/miner-sh/mp.log 2>&1
